<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="检查单" name="first"></el-tab-pane>
      <el-tab-pane label="保养单" name="second"></el-tab-pane>
      <el-tab-pane label="维修/报废单" name="third"></el-tab-pane>
    </el-tabs>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="设备名称" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in options"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备编号" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button @click="handleAdd" size="mini">新增</el-button>
        <el-button @click="handleEdit" size="mini">编辑</el-button>
        <el-button @click="handleDelete" size="mini">删除</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="系统编码" prop="roleName" />
      <el-table-column label="编号" prop="roleKey"  />
      <el-table-column label="设备名称" prop="roleSort" />
      <el-table-column label="下次检查时间" prop="roleSort" width="100" />
      <el-table-column label="下次保养时间" prop="roleSort" width="100" />
      <el-table-column label="工作状态" prop="roleSort" />
      <el-table-column label="出厂编号" prop="roleSort" width="100" />
      <el-table-column label="购入日期" prop="roleSort" width="100" />
      <el-table-column label="安装日期" prop="roleSort" />
      <el-table-column label="出厂日期" prop="roleSort" />
      <el-table-column label="厂家" prop="roleSort" />
      <el-table-column label="使用年限" prop="roleSort" />
      <el-table-column label="所属资源编号" prop="roleSort" width="100" />
      <el-table-column label="供应商" prop="roleSort" />
      <el-table-column label="备注" prop="roleSort" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 单据号表格 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button @click="handleEdit1" size="mini">编辑</el-button>
        <el-button @click="handleDelete1" size="mini">删除</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading1" :data="list1">
      <el-table-column label="单据号" prop="roleName" />
      <el-table-column label="处理状态" prop="roleKey"  />
      <el-table-column label="设备编号" prop="roleSort" />
      <el-table-column label="设备名称" prop="roleSort" width="100" />
      <el-table-column label="经办人" prop="roleSort" width="100" />
      <el-table-column label="制单人" prop="roleSort" />
      <el-table-column label="备注" prop="roleSort" />
    </el-table>

    <pagination
      v-show="total1>0"
      :total="total1"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  data() {
    return {
      // tab
      activeName: 'first',
      // 下拉数据
      options: [],
      // 遮罩层
      loading: true,
      loading1: false,
      // 总条数
      total: 0,
      total1: 0,
      // 表格数据
      list: [],
      list1: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        status: undefined,
        num: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 切换tab页
    handleClick(tab, event) {
      
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams)).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 新增
    handleAdd() {
      if (this.activeName === 'first') {
        this.$emit('change', 'CheckList')
      } else if (this.activeName === 'second') {
        this.$emit('change', 'Maintain')
      } else if (this.activeName === 'third') {
        this.$emit('change', 'Repair')
      }
    },
    // 编辑
    handleEdit() {
      if (this.activeName === 'first') {
        this.$emit('change', 'CheckList')
      } else if (this.activeName === 'second') {
        this.$emit('change', 'Maintain')
      } else if (this.activeName === 'third') {
        this.$emit('change', 'Repair')
      }
    }
  }
};
</script>
